<?php
require_once 'class/EmpRegister.php';

class Attendance extends MySQLCN 
{

    function CreateAttendanceSheet() 
	{
	
		$att1 = new EmpRegister();
		$userRes = $att1->AllListUsr();
		
		for ($i = 0; $i < count($userRes); $i++)
		{
		
		$euid = $userRes[$i]['Login'];
		
		$qry = "INSERT INTO `attendance` ( `empunq_id`, `punch_date`) VALUES ( '{$euid}', '{$_POST['from']}')";
		$this->insert($qry);
			
		}
	
	}
	function UploadInTime($empid,$punch_date1,$punchtime,$late1,$late2) 
	{
	
    $qry = "UPDATE `attendance` SET
              `punch_time_in` = '{$punchtime}',
              `empsts` = '1',
              `latemarksts` = '{$late1}',
              `latediff` = '{$late2}'
               WHERE empunq_id = '{$empid}' AND punch_date = '{$punch_date1}' LIMIT 1";
			$this->insert($qry);
	
	}
	function UploadOutTime() 
	{
    
	
	
	
	}
	function ManualAttendance($EmpID,$curdate) 
	{
	$qry = "UPDATE `attendance` SET
              `punch_time_in` = '{$_POST['entertime']}', 
              `punch_time_out` = '{$_POST['existime']}',
			  `empsts` = '1',
			  `latemarksts` = '1'
               WHERE empunq_id = '{$EmpID}' AND punch_date = '{$curdate}'";
			$this->insert($qry);
			
?>
			<script type="text/javascript"> 
			alert("Added Successfully..!"); 
			history.back(); 
			</script> 
<?  
   }
	function LateMarkCheck() 
	{
    
	
	
	
	}
	
	function DeleteAttendanceSheet($EmpID) {
        $qry = "DELETE FROM `attendance` WHERE punch_date = '{$EmpID}'";
         $this->insert($qry);
?>
			<script type="text/javascript"> 
			alert("Delete Successfully..!"); 
			history.back(); 
			</script> 
<?
  
	}
	
    function ConvertToMinutes($time_string)
	{
	 $hhmmfx = "06:00:00";

	 $arr3= date("H:i:s", strtotime($time_string));
	 $arr4= date("H:i:s", strtotime($hhmmfx));

	 if($arr3 > $arr4){
	 $totdf = "2";
	 $hrslate = $this->getMyTimeDiff($hhmmfx,$time_string);
	 }else{
		$totdf = "1";
	 }
	//return $totdf;
	return array($totdf, $hrslate);
	}
	
	function getMyTimeDiff($t1,$t2)
	{
	  $a1 = explode(":",$t1);
	  $a2 = explode(":",$t2);
	  $time1 = (($a1[0]*60*60)+($a1[1]*60)+($a1[2]));
	  $time2 = (($a2[0]*60*60)+($a2[1]*60)+($a2[2]));
	  $diff = abs($time1-$time2);
	  $hours = floor($diff/(60*60));
	  $mins = floor(($diff-($hours*60))/(60));
	  $secs = floor(($diff-(($hours*60*60)+($mins*60))));
	  $result = $hours.":".$mins.":".$secs;
	  return $result;
	}    
    
}

?>